part of main;

class Delivery {

   static var specialWords = [
      '<b>', 'century', 'fifty', 'half century',
      'sensational', 'fantastic', 'brilliant',
      'wonderful', 'beautiful', 'dropped', 'drop',
      'angry', 'pumped', 'fight', 'abuse'
   ];

   String batter;
   String bowler;
   String comm;
   String dism;
   String event;

   num ball;
   num id;
   num count;

   bool get isSpecial {
      if (event.contains('FOUR')) return true;
      if (event.contains('SIX')) return true;
      if (dism != '') return true;
      for (var each in specialWords) if (comm.contains(each)) return true;
      return false;
   }

   int get hashCode => id;

   Delivery (Map data) {
      batter = data['players'].split(' to ')[1];
      bowler = data['players'].split(' to ')[0];
      comm = data['text'];
      dism = data['dismissal'];
      event = data['event'];

      ball = double.parse(data['overs_actual']);
      id = double.parse(data['overs_unique']);
      count = 0;
   }

   void update (Delivery that) {
      this.comm = that.comm;
      this.dism = that.dism;
      this.event = that.event;
      this.count = 0;
   }

   bool moreData (Delivery that) {
      if (this.comm != that.comm) return true;
      if (this.dism != that.dism) return true;
      if (this.event != that.event) return true;
      return false;
   }

   bool operator == (Delivery that) => this.id == that.id;

   String toString () => '$ball, $bowler to $batter, $event, $comm, $dism';
}
